package com.godofball.medtrack.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.godofball.medtrack.mapper.WarehouseMapper;
import com.godofball.medtrack.pojo.Purchase;
import com.godofball.medtrack.pojo.PurchaseDetail;
import com.godofball.medtrack.pojo.Warehouse;
import com.godofball.medtrack.service.WarehouseService;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse>implements WarehouseService {

    @Override
    public void save(Purchase purchase, List<PurchaseDetail> purchaseDetails){

        LinkedList<Warehouse> warehouses = new LinkedList<>();
        purchaseDetails.forEach(purchaseDetail -> {
            Warehouse warehouse = new Warehouse();
            warehouse.setDrugId(purchaseDetail.getDrugId());
            warehouse.setPurchaseDetailId(purchaseDetail.getId());
            warehouse.setStock(purchaseDetail.getPurchaseCount());
            warehouse.setSalePrice(purchaseDetail.getPurchasePrice());
            warehouse.setStatus(0);
            warehouse.setPurchaseId(purchaseDetail.getPurchaseId());
            warehouse.setManufacturerId(purchase.getManufacturerId());

            warehouses.add(warehouse);
        });

        this.saveBatch(warehouses);

    }

}
